package com.shq.ex1.bus.activity;

import java.util.List;

import com.shq.ex1.R;
import com.shq.ex1.bus.util.UtilMethod;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class ZhanResultActivity extends Activity {

	private List<String> xianByZhanResult = null;
	private ArrayAdapter<String> adapter = null;
	private ListView xianByZhan = null;
	private TextView zhanName = null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.zhan_result);
		xianByZhan = (ListView) findViewById(R.id.xianByZhan);
		zhanName = (TextView) findViewById(R.id.zhanName);
		Intent intent = getIntent();
		final String databasePath = intent.getStringExtra("databasePath");
		String zhandian = intent.getStringExtra("zhandian");
		xianByZhanResult = UtilMethod.getXianByZhan(databasePath, zhandian);
		zhanName.setText("经过" + zhandian + "的公交车有：");
		adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,xianByZhanResult);
		xianByZhan.setAdapter(adapter);
		xianByZhan.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
									long arg3) {
				Intent intent = new Intent();
				intent.putExtra("databasePath", databasePath);
				intent.putExtra("xianlu", arg0.getItemAtPosition(arg2).toString());
				String xianInfoStr = UtilMethod.getXianInfo(databasePath, arg0.getItemAtPosition(arg2).toString() );
				intent.putExtra("xianInfoStr", xianInfoStr);
				intent.setClass(ZhanResultActivity.this, XianResultActivity.class);
				ZhanResultActivity.this.startActivity(intent);
			}
		});
	}

}
